home *** CD-ROM | disk | FTP | other *** search
/ Chip 2004 May / CMCD0504.ISO / Software / Freeware / Programare / gdiplusdelphi / demos / Using Images, Bitmaps, and Metafiles / Loading and Displaying Metafiles / GDITEST42.dpr
Encoding:
Text File  |  2003-10-15  |  2.2 KB  |  89 lines

  1. program GDITEST42;
  2.  
  3. uses
  4.   Classes,
  5.   Windows,
  6.   Messages,
  7.   SysUtils,
  8.   GDIPAPI,
  9.   GDIPOBJ;
  10.  
  11. Procedure OnPaint(DC: HDC);
  12. var
  13.   graphics : TGPGraphics;
  14.   Image: TGPImage;
  15. begin
  16.   graphics := TGPGraphics.Create(DC);
  17.   Image:= TGPImage.Create('..\..\Media\SampleMetafile.emf');
  18.   graphics.DrawImage(Image,0,0);
  19.   Image.Free;
  20.   graphics.Free;
  21. end;
  22.  
  23.  
  24. function WndProc(Wnd : HWND; message : UINT; wParam : Integer; lParam: Integer) : Integer; stdcall;
  25. var
  26.   Handle: HDC;
  27.   ps: PAINTSTRUCT;
  28. begin
  29.   case message of
  30.     WM_PAINT:
  31.       begin
  32.         Handle := BeginPaint(Wnd, ps);
  33.         OnPaint(Handle);
  34.         EndPaint(Wnd, ps);
  35.         result := 0;
  36.       end;
  37.  
  38.     WM_DESTROY:
  39.       begin
  40.         PostQuitMessage(0);
  41.         result := 0;
  42.       end;
  43.  
  44.    else
  45.       result := DefWindowProc(Wnd, message, wParam, lParam);
  46.    end;
  47. end;
  48.  
  49. var
  50.   hWnd     : THandle;
  51.   Msg      : TMsg;
  52.   wndClass : TWndClass;
  53. begin
  54.    wndClass.style          := CS_HREDRAW or CS_VREDRAW;
  55.    wndClass.lpfnWndProc    := @WndProc;
  56.    wndClass.cbClsExtra     := 0;
  57.    wndClass.cbWndExtra     := 0;
  58.    wndClass.hInstance      := hInstance;
  59.    wndClass.hIcon          := LoadIcon(0, IDI_APPLICATION);
  60.    wndClass.hCursor        := LoadCursor(0, IDC_ARROW);
  61.    wndClass.hbrBackground  := HBRUSH(GetStockObject(WHITE_BRUSH));
  62.    wndClass.lpszMenuName   := nil;
  63.    wndClass.lpszClassName  := 'GettingStarted';
  64.  
  65.    RegisterClass(wndClass);
  66.  
  67.    hWnd := CreateWindow(
  68.       'GettingStarted',       // window class name
  69.       'Loading and Displaying Metafiles',       // window caption
  70.       WS_OVERLAPPEDWINDOW,    // window style
  71.       Integer(CW_USEDEFAULT), // initial x position
  72.       Integer(CW_USEDEFAULT), // initial y position
  73.       Integer(CW_USEDEFAULT), // initial x size
  74.       Integer(CW_USEDEFAULT), // initial y size
  75.       0,                      // parent window handle
  76.       0,                      // window menu handle
  77.       hInstance,              // program instance handle
  78.       nil);                   // creation parameters
  79.  
  80.    ShowWindow(hWnd, SW_SHOW);
  81.    UpdateWindow(hWnd);
  82.  
  83.    while(GetMessage(msg, 0, 0, 0)) do
  84.    begin
  85.       TranslateMessage(msg);
  86.       DispatchMessage(msg);
  87.    end;
  88. end.
  89.